const path = require('path');

function resolve(dir) {
    return path.join(__dirname, dir)
}
module.exports = {
    chainWebpack: (config) => {
        config.resolve.alias
            .set('@', resolve('src'))
            .set('assets', resolve('src/assets'))
            .set('components', resolve('src/components'))
            .set('views', resolve('src/views'))
            .set('api', resolve('src/api'))
            .set('styles', resolve('src/styles'))
            .set('utils', resolve('src/utils'))
    },
    devServer: {
        overlay: {
            //让浏览器 overlay 同时显示警告和错误
            warnings: true,
            errors: true
        },
        host: 'localhost',
        port: 8080, //端口号
        https: false, //https:{type:Boolean}
        open: false, //配置后自动启动浏览器
        hotOnly: true, //热更新
        proxy: {
            '/api': {
                target: 'http://120.77.241.190:8081', //配置跨域处理，只有一个代理  http://localhost:8080
                ws: false, //websockets支持
                changeOrigin: true, //开启代理：在本地会创建一个虚拟服务器，然后发送请求的数据，并同时接收请求
                pathRewrite: {
                    "^/api": '/api' //重写匹配的字段，如果不需要在请求路径上，重写为''
                }
            }
        }
    }
}